﻿using UnityEngine;
using System.Collections;
using System;

public class ChainBomb : MonoBehaviour {
	string fragName = "frag";
	Vector3 bulletPos;

	void OnTriggerEnter2D(Collider2D c) {
		GameObject obj = c.gameObject;
		if ("BULLET".Equals (obj.tag)) {
			bulletPos = obj.transform.position;
		}
	}

	void OnDestroy() {
		string name = Common.getObjName (gameObject);
		int no = int.Parse(name.Substring (fragName.Length));
		int target1 = 0;
		int target2 = 0;

//print (no);
		if (no == 14 || no == 15) {
			target1 = 13;
			target2 = 16;
		} else if (no == 10 || no == 11) {
			target1 = 9;
			target2 = 12;
		} else if (no == 6 || no == 7) {
			target1 = 5;
			target2 = 8;
		} else if (no == 2 || no == 3) {
			target1 = 1;
			target2 = 4;
		} else if (no == 5 || no == 9) {
			target1 = 1;
			target2 = 13;
		} else if (target1 == 6 || target2 == 10) {
			target1 = 2;
			target2 = 14;
		} else if (target1 == 7 || target2 == 11) {
			target1 = 3;
			target2 = 15;
		} else if (no == 8 || no == 12) {
			target1 = 4;
			target2 = 16;
		}

		foreach (Transform child in transform.parent) {
			string childName = Common.getObjName(child.gameObject);
			if (childName.Equals(fragName + target1) || childName.Equals("frag" + target2)) {
				Destroy(child.gameObject);
			}
		}
	}
}
